import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CupertinoHomePage extends StatefulWidget {
  @override
  _CupertinoHomePageState createState() => _CupertinoHomePageState();
}

class _CupertinoHomePageState extends State<CupertinoHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('tooltip')),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [buildSegment(), buildSlider()],
      ),
    );
  }

  int _current = 0;
  buildSegment() {
    return Container(
      width: 300,
      margin: EdgeInsets.all(20),
      padding: EdgeInsets.all(10),
      child: CupertinoSegmentedControl(
        children: <int, Widget>{0: Text("全部"), 1: Text("收入"), 2: Text("支出")},
        groupValue: _current,
        onValueChanged: (index) {
          setState(() {
            _current = index;
          });
        },
      ),
    );
  }

  buildSlider() {
    return Container(
      width: 300,
      margin: EdgeInsets.all(20),
      padding: EdgeInsets.all(10),
      child: CupertinoSlidingSegmentedControl(
        children: <int, Widget>{0: Text("全部"), 1: Text("收入"), 2: Text("支出")},
        groupValue: _current,
        onValueChanged: (index) {
          setState(() {
            _current = index;
          });
        },
      ),
    );
  }
}
